package com.controller;

import java.util.*;
import com.entity.*;
import com.client.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;
import java.net.URLDecoder;
import java.net.URLEncoder;

@RestController
public class IndexController {
    @Autowired
    private SmbmsClient sc;

    @RequestMapping(value = "/Long",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,Object> Long(@RequestParam Map<String,String> mp)throws Exception{
       Map<String,Object> rm =new HashMap<>();
        Smbms_user user =sc.Long(mp);
        if(user!=null){
            rm.put("iflogin","登录成功") ;
            rm.put("su",user);
        }else{
            rm.put("iflogin","登录失败");
        }
        return rm;
    }

    @RequestMapping(value = "/info",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,Object> info(@RequestParam Map<String,String> mp)throws Exception{
        Map<String,Object> rm =new HashMap<>();
        System.out.println(mp.get("pname"));
        rm.put("list",sc.info(mp).get("list"));
        return rm;
    }

    @RequestMapping(value = "/providerInfo",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,Object> providerInfo(@RequestParam Map<String,String> mp)throws Exception{
        Map<String,Object> rm =new HashMap<>();

        rm.put("list",sc.providerInfo(mp).get("list"));
        return rm;
    }
    @RequestMapping(value = "/insert",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,Object> insert(Smbms_bill sb)throws Exception{
        Map<String,Object> rm =new HashMap<>();
        int num =sc.insert(sb);
        if(num>0){
            rm.put("err","添加成功！");
        }else {
            rm.put("err","添加失败！");
        }
        return rm;
    }

    @RequestMapping(value = "/delete",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,String> delete(@RequestParam Map<String,String> mp)throws Exception{
        Map<String,String> rm =new HashMap<>();
        System.out.println(mp.get("id"));
        int num =sc.delete(mp);
        if(num>0){
            rm.put("err","删除成功！");
        }else{
            rm.put("err","删除失败！");
        }
        return rm;
    }

    @RequestMapping(value = "/selectD",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,Object> selectD(@RequestParam Map<String,String> mp )throws Exception{
        Map<String,Object> rm =new HashMap<>();
        Smbms_bill sb =sc.selectD(mp);
        rm.put("list",sb);
        return rm;
    }

    @RequestMapping(value = "/update",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,String> update(Smbms_bill sb)throws Exception{
        Map<String,String> rm =new HashMap<>();
        System.out.print(sb);
        int num =sc.update(sb);
        if(num>0){
            rm.put("err","修改成功！");
        }else{
            rm.put("err","修改失败！");
        }
        return rm;
    }

    @RequestMapping(value = "/pDinfo",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Smbms_provider pDinfo(@RequestParam Map<String,String> mp)throws Exception{
        Smbms_provider sp=sc.pDinfo(mp);
        return sp;
    }

    @RequestMapping(value = "/pinsert",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,String> pinsert(Smbms_provider sp)throws Exception{
        Map<String,String> rm = new HashMap<>();
        System.out.print(sp);
        int num =sc.pinsert(sp);
        if(num>0){
            rm.put("err","添加成功！");
        }else{
            rm.put("err","添加失败！");
        }
        return rm;
    }

    @RequestMapping(value = "/pdelete",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String, String> pdelete(@RequestParam Map<String,String> mp)throws Exception{
        Map<String,String> rm = new HashMap<>();
        int num =sc.pdelete(mp);
        if(num>0){
            rm.put("err","删除成功！");
        }else{
            rm.put("err","删除失败！");
        }
        return rm;
    }
    @RequestMapping(value = "/pupdate",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,String> pupdate(Smbms_provider sp)throws Exception{
        Map<String,String> rm = new HashMap<>();
        int num =sc.pupdate(sp);
        if(num>0){
            rm.put("err","修改成功！");
        }else{
            rm.put("err","修改失败！");
        }
        return rm;
    }
    @RequestMapping(value = "/srAll",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public List<Smbms_role> srAll()throws Exception{
        List<Smbms_role> list =sc.srAll();
        return list;
    }

    @RequestMapping(value = "/suAll",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,Object> suAll(@RequestParam Map<String,String> mp)throws Exception{
        Map<String,Object> rm =new HashMap<>();
        System.out.print("-------------------------------------------------  =  "+123 +sc.suAll(mp).get("Total"));
        rm.put("list",sc.suAll(mp).get("list"));
        rm.put("pagenum",sc.suAll(mp).get("pagenum"));
        rm.put("pagecount",sc.suAll(mp).get("pagecount"));
        rm.put("Total",sc.suAll(mp).get("Total"));

        return rm;
    }

    @RequestMapping(value = "/suSelectD",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Smbms_user suSelectD(@RequestParam Map<String,String> mp)throws Exception{
        Smbms_user su =sc.suSelectD(mp);
        return su;
    }

    @RequestMapping(value = "/suDelete",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,String> suDelete(@RequestParam Map<String,String> mp)throws Exception{
        Map<String,String> rm = new HashMap<>();
        int num =sc.suDelete(mp);
        if(num>0){
            rm.put("err","删除成功！");
        }else{
            rm.put("err","删除失败！");
        }
        return rm;
    }

    @RequestMapping(value = "/suInsert",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,String> suInsert(Smbms_user su)throws Exception{
        Map<String,String> rm = new HashMap<>();
        int num =sc.suInsert(su);
        if(num>0){
            rm.put("err","添加成功！");
        }else{
            rm.put("err","添加失败！");
        }
        return rm;
    }
    @RequestMapping(value = "/suUpdate",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,String> suUpdate(Smbms_user su)throws Exception{
        su.setModifydate(new Date());
        Map<String,String> rm = new HashMap<>();
        int num =sc.suUpdate(su);
        if(num>0){
            rm.put("err","修改成功！");
        }else{
            rm.put("err","修改失败！");
        }
        return rm;
    }
}
